﻿using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.Xml.Linq;

using Com.Web.coffinegurunaru.AppLogic.Page;
using System.Text;
using Com.Library.DB.Board;
using System.Collections.Generic;
using System.Web.Script.Serialization;

namespace Com.Web.coffinegurunaru.franchise
{
    public partial class request : WebPage
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            this.LeftMenuType = 5;
        }

		protected override void OnPreRender(EventArgs e)
		{
			base.OnPreRender(e);
 
			if (IsPostBack)
			{
				if (!chkAgree.Checked)
				{
					ClientScript.RegisterStartupScript(this.GetType(), "error", "alert('개인정보의 수집 및 이용목적에 동의해주세요');", true);
					return;
				}

				Dictionary<string, object> jsonData = new Dictionary<string, object>()
				{
					{"Category", category.SelectedValue},
					{"이름", name.Text},
					{"전화", string.Format("{0}-{1}-{2}", phone_no1.Text, phone_no2.Text, phone_no3.Text)},
					{"이메일", receiver_email.Text},
					{"사업경험", add21.Checked ? "있음" : (add22.Checked ? "없음" : "모름")},
					{"점포유무", add31.Checked ? "있음" : (add32.Checked ? "없음" : "모름")},
					{"희망지역", add4.Text},
					{"자금", add5.Text},
					{"주소", string.Format("({0}-{1}) {2}", address_post1.Text, address_post2.Text, address.Text)}
				};

				string json = (new JavaScriptSerializer()).Serialize(jsonData);

				ArticleModel.Create((byte)ArticleModel.BoardSNEnum.Request, title.Text, description.Text, json, 0, this.WebCookies.UserID, string.Empty);

				ClientScript.RegisterStartupScript(this.GetType(), "complete", "alert('등록되었습니다.'); location.href='request.aspx';", true);
				return;
			}
		}
    }
}
